package com.ailink.design.pattern.observer.history;

import java.util.ArrayList;
import java.util.List;

/**
 * 目标对象，它知道观察他的观察者，并提供注册（添加）和删除观察者的接口
 * Created by Administrator on 2018/8/14
 */
public class Subject {
    private List<Observer> observers = new ArrayList<>();

    public void attach(Observer observer) {
        observers.add(observer);
    }

    public void detach(Observer observer) {
        observers.remove(observer);
    }

    protected void notifyObservers() {
        for (Observer observer : observers) {
            observer.update(this);
        }
    }
}
